package com.yulongtian.oneProblemEveryDay.month202301;

/**
 * https://leetcode.cn/problems/calculate-amount-paid-in-taxes/
 *
 * @author yulongTian
 * @create 2023-01-23 20:10
 */
public class Test16 {
    public static void main(String[] args) {
        int[][] arr = {{3, 50}, {7, 10}, {12, 25}};
        int incom = 10;
        System.out.println(calculateTax(arr, incom));
    }

    public static double calculateTax(int[][] brackets, int income) {
        if (income == 0) {
            return 0;
        }
        double ans = 0.0;


        int upper1 = brackets[0][0];
        int percent1 = brackets[0][1];
        if (upper1 > income) {
            upper1 = income;
            ans += 1.0 * upper1 * percent1 / 100;
            return ans;
        }
        ans += 1.0 * upper1 * percent1 / 100;
        for (int i = 1; i < brackets.length; i++) {
            int upper = brackets[i][0];
            int percent = brackets[i][1];
            if (upper > income) {
                upper = income;
                ans += 1.0 * (upper - brackets[i - 1][0]) * percent / 100;
                break;
            }

            ans += 1.0 * (upper - brackets[i - 1][0]) * percent / 100;

        }


        return ans;
    }
}
